{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcf_help.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.min.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
            <div class="layui-form house-table" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">整站页面</label>
                <div class="layui-input-block">
                   <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_site">一键生成</button>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">首页</label>
                <div class="layui-input-block">
                   <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_index">一键生成</button>
                </div>
              </div>
              <div class="layui-form-item">
                 <label class="layui-form-label">栏目页</label>
                 <div class="layui-input-block">
                    <select name="html_typeid" id="html_typeid" lay-ignore>
                         <option value="0">所有栏目…</option>
                         {$select_html|raw}
                    </select>
                    <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_channel">一键生成</button>
                  </div>
              </div>
              <div class="layui-form-item">
                 <label class="layui-form-label">文档页</label>
                 <div class="layui-input-block">
                    <select name="html_arc_typeid" id="html_arc_typeid" lay-ignore>
                         <option value="0">所有文档…</option>
                         {$arc_select_html|raw}
                    </select>
                    <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_article">一键生成</button>
                  </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
</div>
{include file="public/footer"/}
<script>
layui.use(['layer', 'form',], function () {
    var $ = layui.$,
    form = layui.form,
    layer = layui.layer;
    // 监听生成整站
    form.on('submit(up_site)', function(data){
        $.ajax({
            url: "{:url('/channel.Seo/handle')}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (res.status) {
                    var url = "{:url('/channel.Seo/site')}" ;
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: false,content: url});                    
                } else {
                    layer.msg("生成失败！", {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll();
                layer.msg("生成失败！", {icon: 2, time: 1000});
            }
        });
    })
    // 生成首页
    form.on('submit(up_index)', function(data){
        $.ajax({
            url: "{:url('/channel.Seo/handle')}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                if (res.status) {
                    var timestamp1 = Date.parse(new Date());
                    $.ajax({
                        url:"{$Request.domain}/index.php?s=home/Buildhtml/buildIndex",
                        type:'POST',
                        dataType:'json',
                        success:function(data){
                            if(data.msg !== ""){
                                layer.alert(data.msg, {icon: 5, title:false,closeBtn: 0 },function(){
                                    layer.closeAll();
                                });
                            }else{
                                layer.closeAll();
                                var timestamp2 = Date.parse(new Date());
                                var timestamp3 = (timestamp2 - timestamp1) / 1000;
                                if (timestamp3 < 1) timestamp3 = 1; 
                                layer.msg("生成完毕，共耗时：<font color='red'>"+timestamp3+"</font> 秒",{icon:1,time:2000}); 
                            }
                        },
                        error: function(e){
                            layer.closeAll();
                            layer.msg("生成失败！", {icon: 2, time: 1000});
                        }
                    });
                } else {
                    layer.closeAll();
                    layer.msg("生成失败！", {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll();
                layer.msg("生成失败！", {icon: 2, time: 1000});
            }
        });
    })
    // 生成栏目页
    form.on('submit(up_channel)', function(data){
        $.ajax({
            url: "{:url('/channel.Seo/handle')}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (res.status) {
                    var typeid = $("#html_typeid").val(); //栏目id
                    var url = "{:url('/channel.Seo/channel')}?typeid="+typeid;
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px','300px'],fix: false,maxmin:false,content:url}); 
                } else {
                    layer.msg("生成失败！", {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll();
                layer.msg("生成失败，请先提交保存配置！", {icon: 2, time: 1000});
            }
        });
    })
    // 生成文章页
    form.on('submit(up_article)', function(data){
        $.ajax({
            url: "{:url('/channel.Seo/handle')}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (res.status) {
                    var typeid = $("#html_arc_typeid").val();//栏目id
                    var url = "{:url('/channel.Seo/article')}?typeid="+typeid;
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: false,content: url});
                } else {
                    layer.msg("生成失败！", {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll();
                layer.msg("生成失败！", {icon: 2, time: 1000});
            }
        });
    })
});
</script>
</body>
</html>